package com.xz.group12306.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mysql.jdbc.interceptors.SessionAssociationInterceptor;
import com.xz.group12306.business.service.UserService;
import com.xz.group12306.business.service.Impl.UserServiceImpl;
import com.xz.group12306.domain.Cart;
import com.xz.group12306.domain.User;

/**
 * Servlet implementation class ShowOrderServlet
 */
@WebServlet("/ShowOrderServlet")
public class ShowOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowOrderServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	   User  user  =	(User) request.getSession().getAttribute("user");
	    
		
		int pageSize=Integer.parseInt(request.getParameter("pagesize"));
		int start=Integer.parseInt(request.getParameter("starts"));
		UserService userService=new UserServiceImpl();
	    List<Cart> carts=	userService.findCartByUser(user, start, pageSize);
	    
	    request.getSession().setAttribute("carts", carts);
	    
	   response.sendRedirect("user/showOrder.jsp");
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
